package cn.shop.dys.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

import cn.shop.dys.bean.LeftMenuItem;
import cn.shop.lib_common.CommonViewHolder;
import cn.shop.dys.R;

/**
 * 侧滑菜单listview适配器
 * Created by sunjian on 2016/4/16.
 */
public class LeftMenuItemAdapter extends BaseAdapter{
    private Context mContext;
    private List<LeftMenuItem> mLeftMenuItems;

    public LeftMenuItemAdapter(Context mContext, List<LeftMenuItem> mLeftMenuItems) {
        this.mContext = mContext;
        this.mLeftMenuItems = mLeftMenuItems;
    }

    @Override
    public int getCount() {
        return mLeftMenuItems==null?0:mLeftMenuItems.size();
    }

    @Override
    public LeftMenuItem getItem(int position) {
        return mLeftMenuItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CommonViewHolder holder = CommonViewHolder.getCommonViewHolder(convertView, mContext, R.layout.item_left_menu);
        LeftMenuItem leftMenuItem = mLeftMenuItems.get(position);
        holder.getIv(R.id.iv_left_menu).setImageResource(leftMenuItem.getImgID());
        holder.getTv(R.id.tv_left_menu).setText(leftMenuItem.getItemText());
        return holder.convertView;
    }
}
